import { ProColumns, ProTable } from '@/components/Pro';
import { lcControllerGetLcPageEvents } from '@/services/ess/deviceLc';
import { useModel } from '@@/exports';
import dayjs from 'dayjs';
import React from 'react';
import { useIntl } from 'umi';

const EventsInfo: React.FC = () => {
  const { initialState } = useModel('@@initialState');
  const intl = useIntl();

  const columns: ProColumns<any>[] = [
    {
      title: intl.formatMessage({ id: 'data.s/N' }),
      dataIndex: 'pageIndex',
      hideInSearch: true,
      fixed: 'left',
      width: 60,
    },
    {
      title: intl.formatMessage({ id: 'systemManagement.neddTochange.lcType' }),
      dataIndex: 'lcType',
      valueType: 'select',
      initialValue: '1',
      valueEnum: {
        1: {
          text: intl.formatMessage({ id: 'systemManagement.neddTochange.totalLC' }),
        },
        2: {
          text: intl.formatMessage({ id: 'systemManagement.neddTochange.subLC' }),
        },
      },
    },
    {
      title: intl.formatMessage({ id: 'data.acquisitionTime' }),
      dataIndex: 'collectTime',
      key: 'collectTime',
      valueType: 'dateTimeRange',
      initialValue: [dayjs().startOf('day'), dayjs()],
      fixed: 'left',
      width: 100,
      render: (_, record) => {
        return <span>{record.ts}</span>;
      },
    },
    {
      title: intl.formatMessage({ id: 'data.reportingTime' }),
      dataIndex: 'reportTime',
      key: 'reportTime',
      valueType: 'dateTimeRange',
      initialValue: [dayjs().startOf('day'), dayjs()],
      fixed: 'left',
      width: 100,
      render: (_, record) => {
        return <span>{record.time}</span>;
      },
    },
    {
      title: intl.formatMessage({ id: 'data.deviceType' }),
      dataIndex: 'product',
      key: 'product',
      hideInSearch: true,
    },
    {
      title: intl.formatMessage({ id: 'data.deviceFactory' }),
      dataIndex: 'producer',
      key: 'producer',
      hideInSearch: true,
    },
    {
      title: intl.formatMessage({ id: 'data.deviceID' }),
      dataIndex: 'devNum',
      hideInSearch: true,
      width: 90,
    },
    {
      title: intl.formatMessage({ id: 'pcsMonitoring.eventId' }),
      dataIndex: 'code',
      hideInSearch: true,
    },
    {
      title: intl.formatMessage({ id: 'pcsMonitoring.eventStatus' }),
      dataIndex: 'state',
      hideInSearch: true,
    },
    {
      title: intl.formatMessage({ id: 'pcsMonitoring.eventData' }),
      dataIndex: 'event',
      hideInSearch: true,
    },
  ];

  return (
    <>
      <ProTable
        rowKey={'pageIndex'}
        columns={columns}
        request={async (values) => {
          const params = {
            lcType: values.lcType,
            stationId: initialState?.stationId,
            collectStartTime: values?.collectTime ? values?.collectTime[0] : undefined,
            collectEndTime: values?.collectTime ? values?.collectTime[1] : undefined,
            reportStartTime: values?.reportTime ? values?.reportTime[0] : undefined,
            reportEndTime: values?.reportTime ? values?.reportTime[1] : undefined,
            current: values.current,
            pageSize: values.pageSize,
          };
          return await lcControllerGetLcPageEvents(params);
        }}
        toolBarRender={() => []}
        customToolBarClass="global-tabs-custom-tools"
      ></ProTable>
    </>
  );
};

export default EventsInfo;
